import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

public class Servlet extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String password = req.getParameter("pwd");
        if(name.equals("fanshaohua") && password.equals("123456")){
            resp.setContentType("text/html;charset=UTF8");
            PrintWriter out = resp.getWriter();
            try{
                out.print("<html>");
                out.print("<head>");
                out.print("<title>Demo1Servlet</title>");
                out.print("</head>");
                out.print("<body>");
                out.print("<h2>Hello "+ name + ", 欢迎学习servlet" + "</h2>");
                out.print("<h2>The time right now is : " + new Date() + "</h2>");
                out.print("</body>");
                out.print("</html>");
            }finally{
                out.close();
            }
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp);
    }
}
